package com.csun.cmny.provider.controller.rpc;

import com.csun.cmny.provider.model.dto.volunteer.VolunteerQueryDto;
import com.csun.cmny.provider.model.service.UacVolunteerFeignApi;
import com.csun.cmny.provider.model.vo.VolunteerVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.UacVolunteerService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-05-27 10:04
 * @Description: the class uac volunteer feign client
 */
@Slf4j
@RestController
@Api(value = "API - UacVolunteerFeignClient", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacVolunteerFeignClient implements UacVolunteerFeignApi {

    @Resource
    private UacVolunteerService uacVolunteerService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /**
     * 获取志愿者信息
     *
     * @param volunteerId 志愿者Id
     * @return 志愿者信息
     */
    @Override
    public Wrapper getVolunteerByVolunteerId(@RequestParam("volunteerId") Long volunteerId) {

        VolunteerVo volunteerVo = uacVolunteerService.getVolunteerByVolunteerId(volunteerId);

        //return WrapMapper.ok(volunteerVo);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), volunteerVo);
    }

    /**
     * 更新志愿者积分
     *
     * @param volunteerId 志愿者Id
     * @param integral    积分
     *
     * @return the int.
     */
    @Override
    public Wrapper<Integer> updateVolunteerIntegralByVolunteerId(@RequestParam("volunteerId") Long volunteerId,
                                                                 @RequestParam("integral") Integer integral) {

        Integer result = uacVolunteerService.updateVolunteerIntegralByVolunteerId(volunteerId, integral);

        //return WrapMapper.ok(result);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), result);
    }

    /**
     * 查询志愿者列表
     *
     * @param volunteerQueryDto volunteer query dto
     * @return the list.
     */
    @Override
    public Wrapper<List<VolunteerVo>> queryVolunteerListWithPage(@RequestBody VolunteerQueryDto volunteerQueryDto) {

        PageInfo pageInfo = uacVolunteerService.queryVolunteerListWithPage(volunteerQueryDto);

        //return WrapMapper.ok(pageInfo.getList());
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), pageInfo.getList());
    }

    /**
     * 根据志愿者Id集合查询志愿者列表
     *
     * @param volunteerIdList volunteer id list
     * @return the list.
     */
    @Override
    public Wrapper<List<VolunteerVo>> queryVolunteerListByVolunteerIds(@RequestBody List<Long> volunteerIdList) {

        List<VolunteerVo> volunteerVoList = uacVolunteerService.queryVolunteerListByVolunteerIds(volunteerIdList);

        //return WrapMapper.ok(volunteerVoList);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), volunteerVoList);
    }

    /**
     * 根据用户Id查询志愿者信息
     *
     * @param userId
     * @return
     */
    @Override
    public Wrapper<VolunteerVo> getVolunteerByUserId(@RequestParam("userId") Long userId) {

        VolunteerVo volunteerVo = uacVolunteerService.getVolunteerByUserId(userId);

        //return WrapMapper.ok(volunteerVo);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), volunteerVo);
    }


    /**
     * 大数据平台查询志愿者人数
     *
     * @param groupId
     * @return
     */
    @Override
    public Wrapper<Integer> selectVolunteerCount(@RequestParam("groupId") Long groupId) {
        Integer count = uacVolunteerService.selectVolunteerCount(groupId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), count);
    }

}
